package com.tdam2013.grupo12.broadcastReceiver;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.format.Formatter;
import android.util.Log;

public class InformacionRed {
	public static int WIFI = 1;
    public static int DATOS3G = 2;
    public static int NOCONECTADO = 0;
    public static final String ip ="192.168.1.105:8080";      
    public static int getConnectivityStatus(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
 
        NetworkInfo RedActiva = cm.getActiveNetworkInfo();
        if (RedActiva != null) {
            if(RedActiva.getType() == ConnectivityManager.TYPE_WIFI)
                return WIFI;
             
            if(RedActiva.getType() == ConnectivityManager.TYPE_MOBILE)
                return DATOS3G;
        } 
        return NOCONECTADO;
    }
    
    
    
    public static String getConnectivityStatusString(Context context) {
        int conn = InformacionRed.getConnectivityStatus(context);
        
        String estado = null;
        
        if (conn == InformacionRed.WIFI) {
            estado = "Wifi";
        } else if (conn == InformacionRed.DATOS3G) {
            estado = "Datos moviles";
        } else if (conn == InformacionRed.NOCONECTADO) {
            estado = "Sin conexion";
        }
        
        return estado;
    }
    
    public static boolean hayConexion(Context c){
    	if(InformacionRed.getConnectivityStatusString(c).compareTo("Wifi") == 0 || InformacionRed.getConnectivityStatusString(c).compareTo("Datos moviles") == 0 ){
    		return true;
    	}else{
    		return false;
    	}
    }
}
